VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Nomads_Backup"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Dim Me_ActiveDocumentPath As String

Private Sub Class_Initialize()
    Me_ActiveDocumentPath = ActiveDocument.FullName
End Sub

Function Create()
    ' save current document
    m_SaveCurrentDocument
    ' save as backup
    m_CreateBackupDocument
    ' save as original document
    m_SaveAsOriginalDocument
End Function

Private Function m_SaveCurrentDocument()
    ActiveDocument.Save
End Function

Private Function m_SaveAsOriginalDocument()
    ChangeFileOpenDirectory m_GetCurrentFolder
    ActiveDocument.SaveAs FileName:=Me_ActiveDocumentPath, AddToRecentFiles:=False
End Function

Private Function m_CreateBackupDocument()
    ChangeFileOpenDirectory m_GetCurrentFolder
    ActiveDocument.SaveAs FileName:=m_GetBackupPath, AddToRecentFiles:=False
End Function

Private Function m_GetCurrentFolder() As String
    Dim FilePath As String
    Dim FileName As String
    Dim FolderPath As String
    
    FilePath = Me_ActiveDocumentPath
    FileName = Dir(FilePath)
    FolderPath = Mid(FilePath, 1, Len(FilePath) - Len(FileName))
    Debug.Print FileName
    Debug.Print FolderPath
    m_GetCurrentFolder = FolderPath
End Function

Private Function m_GetBackupPath() As String
    Dim FilePath As String
    Dim FileName As String
    Dim FolderPath As String
    Dim FileExtension As String
    Dim FileNameWithoutExtension As String
    Dim FileBackupName As String
    Dim FileBackupPath As String
    
    FilePath = Me_ActiveDocumentPath
    FileName = Dir(FilePath)
    FolderPath = Mid(FilePath, 1, Len(FilePath) - Len(FileName))
    FileExtension = Mid(FileName, InStr(FileName, "."))
    FileNameWithoutExtension = Mid(FileName, 1, Len(FileName) - Len(FileExtension))
    
    FileBackupName = FileNameWithoutExtension & _
        "-" & Format(Now, "yyyymmdd-hhmmss") & _
        FileExtension
    FileBackupPath = FolderPath & "\" & FileBackupName
    m_GetBackupPath = FileBackupPath
End Function
